package com.fdb.efp.nls.service.impl;

import com.fdb.basic.framework.core.base.FrameworkService;
import com.fdb.efp.nls.service.dao.DwBaiduLoanRateTempDao;
import com.fdb.efp.nls.service.domain.DwBaiduLoanRateTemp;
import com.fdb.efp.nls.service.facade.DwBaiduLoanRateTempService;
import com.fdb.efp.nls.service.vo.DwBaiduLoanRateTempVO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Objects;

/**
 * Service Impl: 贷款利息汇率临时表服务实现
 * 
 * @author ligm
 * @date 2019-05-02
 */
@Service("dwBaiduLoanRateTempService")
public class DwBaiduLoanRateTempServiceImpl implements DwBaiduLoanRateTempService, FrameworkService {

	private static Logger logger = LoggerFactory.getLogger(DwBaiduLoanRateTempServiceImpl.class);

	@Autowired
	private DwBaiduLoanRateTempDao dwBaiduLoanRateTempDao;

	/**
	 * 新增数据
	 * 
	 * @param inDwBaiduLoanRateTempVo
	 * @return
	 */
	public int insertDwBaiduLoanRateTemp(DwBaiduLoanRateTempVO inDwBaiduLoanRateTempVo) {
		logger.debug("当前新增数据为:" + inDwBaiduLoanRateTempVo.toString());
		int num = 0;
		try {
			DwBaiduLoanRateTemp dwBaiduLoanRateTemp = new DwBaiduLoanRateTemp();
			beanCopy(inDwBaiduLoanRateTempVo, dwBaiduLoanRateTemp);
			num = dwBaiduLoanRateTempDao.insertDwBaiduLoanRateTemp(dwBaiduLoanRateTemp);
		} catch (Exception e) {
			logger.error("新增数据发生异常!", e);
			num = -1;
		}
		logger.debug("当前新增数据条数为:" + num);
		return num;
	}

	/**
	 * 根据主键删除信息
	 * 
	 * @param inDwBaiduLoanRateTempVo
	 * @return
	 */
	public int deleteByPk(DwBaiduLoanRateTempVO inDwBaiduLoanRateTempVo) {
		logger.debug("当前删除数据条件为:" + inDwBaiduLoanRateTempVo);
		int num = 0;
		try {
			DwBaiduLoanRateTemp dwBaiduLoanRateTemp = new DwBaiduLoanRateTemp();
			beanCopy(inDwBaiduLoanRateTempVo, dwBaiduLoanRateTemp);
			num = dwBaiduLoanRateTempDao.deleteByPk(dwBaiduLoanRateTemp);
		} catch (Exception e) {
			logger.error("删除数据发生异常!", e);
			num = -1;
		}
		logger.debug("根据条件:" + inDwBaiduLoanRateTempVo + "删除的数据条数为" + num);
		return num;
	}

	/**
	 * 根据主键更新信息
	 * 
	 * @param inDwBaiduLoanRateTempVo
	 * @return
	 */
	public int updateByPk(DwBaiduLoanRateTempVO inDwBaiduLoanRateTempVo) {
		logger.debug("当前修改数据为:" + inDwBaiduLoanRateTempVo.toString());
		int num = 0;
		try {
			DwBaiduLoanRateTemp dwBaiduLoanRateTemp = new DwBaiduLoanRateTemp();
			beanCopy(inDwBaiduLoanRateTempVo, dwBaiduLoanRateTemp);
			num = dwBaiduLoanRateTempDao.updateByPk(dwBaiduLoanRateTemp);
		} catch (Exception e) {
			logger.error("修改数据发生异常!", e);
			num = -1;
		}
		logger.debug("根据条件:" + inDwBaiduLoanRateTempVo + "修改的数据条数为" + num);
		return num;
	}

	/**
	 * 根据主键查询详情
	 * 
	 * @param dwBaiduLoanRateTemp
	 * @return
	 */
	public DwBaiduLoanRateTempVO queryByPk(DwBaiduLoanRateTempVO inDwBaiduLoanRateTempVo) {

		logger.debug("当前查询参数信息为:" + inDwBaiduLoanRateTempVo);
		try {
			DwBaiduLoanRateTemp queryDwBaiduLoanRateTemp = new DwBaiduLoanRateTemp();
			beanCopy(inDwBaiduLoanRateTempVo, queryDwBaiduLoanRateTemp);
			DwBaiduLoanRateTemp queryRslDwBaiduLoanRateTemp = dwBaiduLoanRateTempDao.queryByPk(queryDwBaiduLoanRateTemp);
			if (Objects.nonNull(queryRslDwBaiduLoanRateTemp)) {
				DwBaiduLoanRateTempVO outDwBaiduLoanRateTempVo = beanCopy(queryRslDwBaiduLoanRateTemp, new DwBaiduLoanRateTempVO());
				logger.debug("当前查询结果为:" + outDwBaiduLoanRateTempVo.toString());
				return outDwBaiduLoanRateTempVo;
			} else {
				logger.debug("当前查询结果为空!");
			}
		} catch (Exception e) {
			logger.error("查询数据发生异常!", e);
		}
		return null;
	}

	/**
	 * 一级数据权限
	 * 
	 * @param dwBaiduLoanRateTemp
	 * @return
	 */
	@SuppressWarnings("unchecked")
	public List<DwBaiduLoanRateTempVO> queryAllByLevelOne(DwBaiduLoanRateTempVO dwBaiduLoanRateTempVo) {
		logger.debug("查看当前用户对应的数据信息的参数信息为:");
		List<DwBaiduLoanRateTempVO> list = null;
		try {
			List<DwBaiduLoanRateTemp> dwBaiduLoanRateTemps = dwBaiduLoanRateTempDao.queryAllByLevelOneByPage(dwBaiduLoanRateTempVo);
			logger.debug("查看当前用户对应的数据信息的结果集数量为:" + dwBaiduLoanRateTemps.size());
			pageSet(dwBaiduLoanRateTemps, dwBaiduLoanRateTempVo);
			list = (List<DwBaiduLoanRateTempVO>) beansCopy(dwBaiduLoanRateTemps, DwBaiduLoanRateTempVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}

		return list;

	}

	/**
	 * 二级数据权限
	 * 
	 * @param dwBaiduLoanRateTemp
	 * @return
	 */
	@SuppressWarnings("unchecked")
	public List<DwBaiduLoanRateTempVO> queryAllByLevelTwo(DwBaiduLoanRateTempVO dwBaiduLoanRateTempVo) {
		logger.debug("查看当前用户及所属机构对应的数据信息的参数信息为:");
		List<DwBaiduLoanRateTemp> dwBaiduLoanRateTemps = dwBaiduLoanRateTempDao.queryAllByLevelTwoByPage(dwBaiduLoanRateTempVo);
		logger.debug("查看当前用户及所属机构对应的数据信息的结果集数量为:" + dwBaiduLoanRateTemps.size());
		List<DwBaiduLoanRateTempVO> list = null;
		try {
			pageSet(dwBaiduLoanRateTemps, dwBaiduLoanRateTempVo);
			list = (List<DwBaiduLoanRateTempVO>) beansCopy(dwBaiduLoanRateTemps, DwBaiduLoanRateTempVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}

		return list;

	}

	/**
	 * 三级数据权限
	 * 
	 * @param dwBaiduLoanRateTemp
	 * @return
	 */
	@SuppressWarnings("unchecked")
	public List<DwBaiduLoanRateTempVO> queryAllByLevelThree(DwBaiduLoanRateTempVO dwBaiduLoanRateTempVo) {
		logger.debug("查看当前用户所在机构及下属机构对应的数据信息的参数信息为:");
		List<DwBaiduLoanRateTemp> dwBaiduLoanRateTemps = dwBaiduLoanRateTempDao.queryAllByLevelThreeByPage(dwBaiduLoanRateTempVo);
		logger.debug("查看当前用户所在机构及下属机构对应的数据信息的结果集数量为:" + dwBaiduLoanRateTemps.size());
		List<DwBaiduLoanRateTempVO> list = null;
		try {
			pageSet(dwBaiduLoanRateTemps, dwBaiduLoanRateTempVo);
			list = (List<DwBaiduLoanRateTempVO>) beansCopy(dwBaiduLoanRateTemps, DwBaiduLoanRateTempVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}

		return list;
	}

	/**
	 * 四级数据权限
	 * 
	 * @param dwBaiduLoanRateTemp
	 * @return
	 */
	@SuppressWarnings("unchecked")
	public List<DwBaiduLoanRateTempVO> queryAllByLevelFour(DwBaiduLoanRateTempVO dwBaiduLoanRateTempVo) {
		logger.debug("【预留，便于后续自定义 】信息的参数信息为:");
		List<DwBaiduLoanRateTemp> dwBaiduLoanRateTemps = dwBaiduLoanRateTempDao.queryAllByLevelFourByPage(dwBaiduLoanRateTempVo);
		logger.debug("【预留，便于后续自定义 】信息的结果集数量为:" + dwBaiduLoanRateTemps.size());
		List<DwBaiduLoanRateTempVO> list = null;
		try {
			pageSet(dwBaiduLoanRateTemps, dwBaiduLoanRateTempVo);
			list = (List<DwBaiduLoanRateTempVO>) beansCopy(dwBaiduLoanRateTemps, DwBaiduLoanRateTempVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}

		return list;
	}

	/**
	 * 五级数据权限
	 * 
	 * @param dwBaiduLoanRateTemp
	 * @return
	 */
	@SuppressWarnings("unchecked")
	public List<DwBaiduLoanRateTempVO> queryAllByLevelFive(DwBaiduLoanRateTempVO dwBaiduLoanRateTempVo) {
		logger.debug("【预留，便于后续自定义 】信息的参数信息为:");
		List<DwBaiduLoanRateTemp> dwBaiduLoanRateTemps = dwBaiduLoanRateTempDao.queryAllByLevelFiveByPage(dwBaiduLoanRateTempVo);
		logger.debug("【预留，便于后续自定义 】信息的结果集数量为:" + dwBaiduLoanRateTemps.size());
		List<DwBaiduLoanRateTempVO> list = null;
		try {
			pageSet(dwBaiduLoanRateTemps, dwBaiduLoanRateTempVo);
			list = (List<DwBaiduLoanRateTempVO>) beansCopy(dwBaiduLoanRateTemps, DwBaiduLoanRateTempVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}

		return list;
	}

	/**
	 * 
	 * 分页查询【贷款利息汇率临时表】 <br>
	 * 0.1:ludayong:2019年3月23日 下午12:11:04:新增 <br>
	 * 
	 * @author ludayong
	 * @since 2019年3月23日 下午12:11:04
	 * @date 2019年3月23日 下午12:11:04
	 * @version 0.1
	 */
	@SuppressWarnings("unchecked")
	@Override
	public List<DwBaiduLoanRateTempVO> queryByPage(DwBaiduLoanRateTempVO dwBaiduLoanRateTempVO) {
		String msg1 = "分页查询贷款利息汇率临时表";
		logger.debug(msg1, "message {}");
		List<DwBaiduLoanRateTempVO> list = null;
		try {
			List<DwBaiduLoanRateTemp> DwBaiduLoanRateTemps = dwBaiduLoanRateTempDao.queryByPage(dwBaiduLoanRateTempVO);
			list = (List<DwBaiduLoanRateTempVO>) beansCopy(DwBaiduLoanRateTemps, DwBaiduLoanRateTempVO.class);
		} catch (Exception e) {
			logger.error("查询数据发生异常!", e);

		}
		if(list != null) {
			String msg2 = "查询的数据为大小为 " + list.size();
			logger.debug(msg2, "message {}");
		}
		return list;
	}

	/**
	 * 
	 * 统计【贷款利息汇率临时表】数据量 <br>
	 * 0.1:ludayong:2019年3月23日 下午12:11:10:新增 <br>
	 * 
	 * @author ludayong
	 * @since 2019年3月23日 下午12:11:10
	 * @date 2019年3月23日 下午12:11:10
	 * @version 0.1
	 */
	@Override
	public int queryCount() {
		String msg1 = "查询【贷款利息汇率临时表】表中数据量大小";
		logger.debug(msg1, "message {}");
		int num = 0;
		try {
			num = dwBaiduLoanRateTempDao.queryCount();
		} catch (Exception e) {
			String msg2 = "查询【贷款利息汇率临时表】表中数据量大小出错" + e;
			logger.debug(msg2, "message {}");
			num = -1;
		}
		return num;
	}
}
